﻿using System;
using System.Collections.Generic;
using System.Text;
using Task.Common.Interface;
using Task.Common.Entity;
using IBatisNet.DataMapper;
using Common.Service;
using System.Collections;
using Common.Logging;

namespace Task.Logic
{
    class TaskLogic:ITask
    {    
        /// <summary>
        /// 获取待办任务列表
        /// </summary>
        /// <param name="where"></param>
        /// <param name="start"></param>
        /// <param name="limit"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        public IList GetList(string where, int start, int limit, out int count)
        {
            Hashtable table = new Hashtable();
            //table.Add("taskid", "05041162c187f3a8e84ba5df1f54be");//参数--条件
            //查询条件的形式 为 [表字段名=参数值; ...]
            if (!String.IsNullOrEmpty(where))
            {
                where = where.TrimEnd(';');//格式化 条件 语句
                string[] strWheres = where.Split(';');//
                for (int i = 0; i < strWheres.Length; i++)
                {
                    string str = strWheres[i];
                    string[] strParems = str.Split('!');
                    table.Add(strParems[0], strParems[1]);//参数 将参数信息添加到hashtable中
                }
            }
            IList list = DataHelper.Instance().GetList("TaskLogic_GetList", table,start,limit);
            count = list.Count;
            
            return list;
        }

        public TaskEntity Get(string taskId)
        {
            return DataHelper.Instance().Get<TaskEntity>("TaskLogic_Get", taskId);
        }

        public void Insert(TaskEntity entity)
        {
            DataHelper.Instance().Insert("TaskLogic_Insert", entity);
        }

        public void Update(TaskEntity entity)
        {
            DataHelper.Instance().Update("TaskLogic_Update", entity);
        }

        public bool Exists(string taskId)
        {
            throw new NotImplementedException();
        }

        public void Delete(string taskId)
        {
            DataHelper.Instance().Delete("TaskLogic_Delete", taskId);
        }



        public IList GetFinishedList(string where, int start, int limit, out int count)
        {
            Hashtable table = new Hashtable();
            //table.Add("taskid", "05041162c187f3a8e84ba5df1f54be");//参数--条件
            //查询条件的形式 为 [表字段名=参数值; ...]
            if (!String.IsNullOrEmpty(where))
            {
                where = where.TrimEnd(';');//格式化 条件 语句
                string[] strWheres = where.Split(';');//
                for (int i = 0; i < strWheres.Length; i++)
                {
                    string str = strWheres[i];
                    string[] strParems = str.Split('!');
                    table.Add(strParems[0], strParems[1]);//参数 将参数信息添加到hashtable中
                }
            }
            IList list = DataHelper.Instance().GetList("FinishedTask_GetList", table, start, limit);
            count = list.Count;

            return list;
        }
    }
}
